package com.wrial.kind.sort;
/*
 * @Author  Wrial
 * @Date Created in 8:54 2020/8/8
 * @Description
 */

import java.util.HashMap;

public class BubbleSort {


    //如果flag比较了一个循环都没变，就直接break
    public int[] sortArray(int[] nums) {

        for (int i = 0; i < nums.length; i++) {  //控制次数
            boolean flag = true;
            for (int j = 0; j < nums.length - i - 1 ; j++) {  //负责相邻交换并空间缩小
                if (nums[j] > nums[j + 1]) {
                    flag = false;
                    int temp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = temp;
                }
            }
           if (flag) break;
        }
        return nums;
    }

    public static void main(String[] args) {
    }
}
